<template>
  <div>
    {{ show ? '正在登陆中' : '' }}
  </div>
</template>

<script lang="ts" setup>
  import useUserStore from '@/store/modules/user'
  import { UserState } from '@/store/types'
  import { randomString } from '@/utils'
  import { ref } from 'vue'
  import { useRouter } from 'vue-router'
  const userStore = useUserStore()
  const router = useRouter()
  const obj = {
    nickName: '总控',
    userName: '总控',
    token: randomString(100),
  }
  const show = ref(false)
  const regex = /token=([^&]*)/
  if (regex.test(window.location.href)) {
    const token = localStorage.getItem('user-info')
    if (token) {
      show.value = true
      userStore.changeCommentlist([])
      router
        .replace({
          path: '/home/index',
        })
        .then(() => {})
    } else {
      show.value = true
      userStore.changeCommentlist([])
      userStore.saveUser(obj as UserState).then(() => {
        router
          .replace({
            path: '/home/index',
          })
          .then(() => {})
      })
    }
  }
  console.log(window.location.href)
</script>

<style lang="scss" scoped></style>
